import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)
// 把这段代码直接粘贴到router/index.js中的Vue.use(VueRouter)之前
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
  return originalPush.call(this, location).catch(err => {})
};
const routes = [{
    path: '/home',
    name: 'home',
    component: Home
  },
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/order',
    name: 'order',
    component: () => import('../views/Order.vue')
  }, {
    path: '/free',
    name: 'free',
    component: () => import('../views/Free.vue')
  }, {
    path: '/user',
    name: 'user',
    component: () => import('../views/User.vue'),
    redirect: '/user/cart',
    children: [{
      path: '/user/cart',
      component: () => import('../components/user/Cart.vue')
    }, ]
  },
  {
    path: '/goods',
    name: 'goods',
    component: () => import('../views/Goods.vue')
  }, {
    path: '/details',
    name: 'details',
    component: () => import('../views/Details.vue')
  },
  {
    path: '*',
    component: () => import('../views/Error.vue')
  },


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router